package com.itboye.boyeshoping

import android.app.Application
import android.content.Context
import android.support.multidex.MultiDex
import android.widget.Toast
import com.alibaba.baichuan.android.trade.AlibcTradeSDK
import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback
import com.alibaba.baichuan.trade.biz.AlibcTradeBiz
import com.alibaba.baichuan.trade.common.AlibcTradeCommon
import com.alibaba.baichuan.trade.common.adapter.ut.AlibcUserTracker
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.toolbox.Volley
import com.ut.mini.internal.UTTeamWork
import java.util.HashMap

/**
 * Created by Administrator on 2018/6/26 0026.
 */

class MyApplication : Application() {

    companion object {
        lateinit var app:MyApplication
        private lateinit var queue: RequestQueue
        fun <T> addRequest(request: Request<T>) {
            request.addMarker("itboye")
            getQueue()!!.add(request)
        }
        /**
         * @return the queue
         */
        fun getQueue(): RequestQueue {
            return queue
        }
    }
    override fun onCreate() {
        super.onCreate()
        app = this
        //注册
        queue = Volley.newRequestQueue(app)
//        MultiDex.install(this)
//        AlibcTradeCommon.turnOnDebug()
//        AlibcTradeBiz.turnOnDebug()
        //电商SDK初始化
        AlibcTradeSDK.asyncInit(this@MyApplication, object : AlibcTradeInitCallback {
            override fun onSuccess() {
                Toast.makeText(this@MyApplication, "初始化成功", Toast.LENGTH_SHORT).show()

//                val utMap:HashMap<String,String> = HashMap()
//                utMap["debug_api_url"] = "http://muvp.alibaba-inc.com/online/UploadRecords.do"
//                utMap["debug_key"] = "baichuan_sdk_utDetection"
//                UTTeamWork.getInstance().turnOnRealTimeDebug(utMap)
//                AlibcUserTracker.getInstance().sendInitHit4DAU("19", "3.1.1.100")

            }

            override fun onFailure(code: Int, msg: String) {
                Toast.makeText(this@MyApplication, "初始化失败,错误码=$code / 错误消息=$msg", Toast.LENGTH_SHORT).show()
            }
        })


    }

     override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }



}
